<?php
session_start();
$userid=$_SESSION['userid'];
include ('mysqli_connect.php');


?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <title>影视管理 || 增加影视信息</title>
</head>
<body>
<nav class="navbar navbar-default navbar-static-top" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="#">影视管理系统</a>
        </div>
        <div>
            <ul class="nav navbar-nav">
                <li class="active"><a href="admin_index.php">主页</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">影视管理<b class="caret"></b>
                    </a>
                    <ul class="dropdown-menu">
                        <li><a href="admin_all_movie.php">全部影视</a></li>
                        <li><a href="admin_movie_add.php">增加影视信息</a></li>
                    </ul>
                </li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">用户管理<b class="caret"></b>
                    </a>
                    <ul class="dropdown-menu">
                        <li><a href="admin_user.php">全部用户</a></li>
                        <li><a href="admin_user_add.php">增加用户</a></li>
                        <?php 
                            if($_SESSION['super_manager']==2){
                                echo "<li><a href='super_admin_add.php'>增加管理员</a></li>";
                            }
                        ?>
                    </ul>
                </li>
                <li><a href="admin_repass.php">密码修改</a></li>
                <li><a href="index.php">退出</a></li>
            </ul>
        </div>
    </div>
</nav>
<h1 style="text-align: center"><strong>增加影视信息</strong></h1>
<div style="padding: 10px 500px 10px;">
    <form  action="admin_movie_add.php" method="POST" style="text-align: center" class="bs-example bs-example-form" role="form">
        <div id="login">
            <div class="input-group"><span class="input-group-addon">导演</span><input name="nmovie_director" type="text" placeholder="请输入导演" class="form-control"></div><br/>
            <div class="input-group"><span class="input-group-addon">地区</span><input name="nmovie_regiou" type="text" placeholder="请输入地区" class="form-control"></div><br/>
            <div class="input-group"><span class="input-group-addon">上映时间</span><input name="nrelease_time" type="text" placeholder="请输入上映时间" class="form-control"></div><br/>
            <div class="input-group"><span class="input-group-addon">语言</span><input name="nmovie_language" type="text" placeholder="请输入语言" class="form-control"></div><br/>
            <div class="input-group"><span class="input-group-addon">时长</span><input name="nmovie_duration" type="text" placeholder="请输入时长" class="form-control"></div><br/>
            <div class="input-group"><span class="input-group-addon">中文名</span><input name="nmovie_Chinese_name" type="text" placeholder="请输入中文名" class="form-control"></div><br/>
            <div class="input-group"><span class="input-group-addon">英文名</span><input name="nmovie_English_name" type="text" placeholder="请输入英文名" class="form-control"></div><br/>
            <div class="input-group"><span class="input-group-addon">评分</span><input name="nmovie_marking" type="text" placeholder="请输入评分" class="form-control"></div><br/>
            <div class="input-group"><span class="input-group-addon">简介</span><input name="nmovie_intro" type="text" placeholder="请输入简介" class="form-control"></div><br/>
            <label><input type="submit" value="添加" class="btn btn-default"></label>
            <label><input type="reset" value="重置" class="btn btn-default"></label>
        </div>
    </form> 
</div>
<?php

if ($_SERVER["REQUEST_METHOD"] == "POST")
{
    #$nnam = $_POST["nmovie_id"];
    $naut = $_POST["nmovie_director"];
    $npubl = $_POST["nmovie_regiou"];
    $nisb = $_POST["nrelease_time"];
    $nint = $_POST["nmovie_language"];
    $nlan = $_POST["nmovie_duration"];
    $npri = $_POST["nmovie_Chinese_name"];
    $npubd = $_POST["nmovie_English_name"];
    $ncla = $_POST["nmovie_marking"];
    $npre = $_POST["nmovie_intro"];

    $sql_temp="select max(movie_id) as movie_id from movie_information_table;";
    $res_temp=mysqli_query($dbc,$sql_temp);
    $movieid=mysqli_fetch_assoc($res_temp)['movie_id'];
    $movieid=(int)$movieid;
    $movieid=$movieid+1;
    $movieid=(string)$movieid;

    $sqla="insert into movie_information_table 
    VALUES ('{$movieid}','{$naut}','{$npubl}','{$nisb}','{$nint}',{$nlan},'{$npri}','{$npubd}',{$ncla},'{$npre}');";
    $resa=mysqli_query($dbc,$sqla);
    
    if($resa==1)
    {

        echo "<script>alert('添加成功！ 影视ID为: {$movieid}')</script>";
        echo "<script>window.location.href='admin_all_movie.php'</script>";

    }
    else
    {
        echo "<script>alert('添加失败！请重新输入！');</script>";

    }

}

?>
</body>
</html>
